<template>
    <div id="sunhao">
      <div id="water"></div>
      <div id="dian"></div>
    </div>
</template>

<script>
import { allwater, alldian } from "../../apis/rrk/link";
import * as echarts from "echarts";
export default {
  data() {
    return {
      water: [],
      waters: [],
    };
  },
  mounted() {
    // 请求用水量
    allwater().then((res) => {
      // console.log(res.data.data);

      var myChart = echarts.init(document.getElementById("water"));
      var option = {
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        title: {
          text: "总用水图",
        },
        tooltip: {},
        legend: {
          data: [""],
        },
        xAxis: {
          data: res.data.data.map((item) => item.name),
        },
        yAxis: {},
        series: [
          {
            name: "用量",
            type: "bar",
            data: res.data.data.map((item) => item.value),
            color: "#67c23a",
            label: {
              show: true,
            },
          },
        ],
      };
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
    });

    // 请求用电量
    alldian().then((res) => {
      // console.log(res.data.data);
      var myCharttwo = echarts.init(document.getElementById("dian"));
      var option = {
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        title: {
          text: "总用电图",
          left: "left",
        },
        tooltip: {
          trigger: "item",
        },
        series: [
          {
            type: "pie",
            data: res.data.data,
            roseType: "area",
          },
        ],
        roseType: "area",
      };

      // 使用刚指定的配置项和数据显示图表。
      myCharttwo.setOption(option);
    });
  },
};
</script>

<style scoped lang="scss">

  #sunhao {
    width: 40%;
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    justify-content: flex-start;
    div {
      width: 100%;
      height: 200px;
      margin-bottom: 20px;
      margin-left: 30px;
      background-color: #fff;
    }
  }
</style>